package davidtps.godutch.adapter;

import davidtps.godutch.activity.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AdapterMainGridView extends BaseAdapter {

	private Context mContext=null;
	private class Holder{
		ImageView ivItemImage;
		TextView tvItemName;
	}
	
	private String[] mImageResourceName = new String[]{};
	
	public AdapterMainGridView(Context pContext){
		mContext = pContext;
		mImageResourceName = new String[]{
				mContext.getString(R.string.main_body_recordConsume),
				mContext.getString(R.string.main_body_queryConsume),
				mContext.getString(R.string.main_body_statisticsManager),
				mContext.getString(R.string.main_body_accoutBookManager),
				mContext.getString(R.string.main_body_categoryManager),
				mContext.getString(R.string.main_body_staffManager)
				
		};
	}
	
	private int[] mImageResourceId = new int[]{
			R.drawable.grid_payout,
			R.drawable.grid_bill,
			R.drawable.grid_report,
			R.drawable.grid_account_book,
			R.drawable.grid_category,
			R.drawable.grid_user
	};
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mImageResourceId.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Holder _Holder = null;
		if(convertView==null){
			convertView = LayoutInflater.from(mContext).inflate(R.layout.layout_body_item, null);
			
			_Holder = new Holder();
			_Holder.ivItemImage = (ImageView)convertView.findViewById(R.id.ivItemImage);
			_Holder.tvItemName = (TextView)convertView.findViewById(R.id.tvItemName);
			convertView.setTag(_Holder);
			
		}else{
			_Holder = (Holder)convertView.getTag();
		}
		
		_Holder.ivItemImage.setImageResource(mImageResourceId[position]);
//		_Holder.ivItemImage.setLayoutParams(new LinearLayout.LayoutParams(50,50));
//		_Holder.ivItemImage.setScaleType(ImageView.ScaleType.FIT_XY);
		
		_Holder.tvItemName.setText(mImageResourceName[position]);
		
		return convertView;
	}

}
